﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml.Linq;
using BTN04.DTO;
using BTN04.BUS;
using System.Collections.Generic;

namespace BTN04.ADMIN
{
    public partial class WebForm1 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if(!IsPostBack)
            {
                LoaiSanPhamDTO lsp = new LoaiSanPhamDTO();
                List<LoaiSanPhamDTO> lst = new List<LoaiSanPhamDTO>();
                ListItem item = new ListItem();
                item.Value = "0";
                item.Text = "Chon";
                LoaiSanPhamBUS lspBUS = new LoaiSanPhamBUS();
                lst = lspBUS.DanhSachLoaiSanPham();
                DropDownList1.Items.Add(item);
                for (int i = 0; i < lst.Count;i++ )
                {
                    item = new ListItem();
                    item.Value = lst[i].MaLoaiSanPham.ToString();
                    item.Text = lst[i].TenLoaiSanPham;
                    DropDownList1.Items.Add(item);
                }
            }
            if (Request.QueryString["MaLoaiSanPham"] == null)
            {
                GridView1.Visible = false;
            }
            else
            {
                GridView1.Visible = true;
                SanPhamBUS spBUS = new SanPhamBUS();
                DataTable dt = new DataTable();
                int MaLoaiSanPham = Convert.ToInt32(Request.QueryString["MaLoaiSanPham"]);
                dt = spBUS.SanPhamTop10SoLuongBanTheoLoaiSanPham(MaLoaiSanPham);
                GridView1.DataSource = dt;
                GridView1.DataBind();

            }

        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            int value = DropDownList1.SelectedIndex;
            int _maLoaiSanPham;
            if(value == 0)
            { 
            }
            else
            {
                _maLoaiSanPham = Convert.ToInt32(DropDownList1.Items[value].Value);
                if (_maLoaiSanPham != 0)
                {
                    Response.Redirect("thongkesanphambanchaytopmuoitheoloaisanpham.aspx?MaLoaiSanPham=" + _maLoaiSanPham.ToString());
                }
            }
        }
    }
}
